// pages/applications/applications.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    role: 0,
    list_height: 0,
    setting_btn_height: 0,
    app_list: [{
      name: "创客马拉松",
      photo_url: "/images/hammer.png"
    },
    {
      name: "组队助手",
      photo_url: "/images/addteam.png",
    },
    {
      name: "火花画布",
      photo_url: "/images/canvasIcon.png",
    },
    {
      name: "实验验收",
      photo_url: "/images/qiandao.png",
    }]
  },

  setting: function () {
    wx.navigateTo({
      url: '../set_admin_teacher/set_admin_teacher',
    })
  },

  choose: function (e) {
    console.log("applications: ", e)
    var index = e.currentTarget.dataset.idx
    console.log("applications: ", index)
    if (index == 0) {
      wx.navigateTo({
        url: '../hackson/hackson',
      })
    } else if (index == 1) {
      wx.navigateTo({
        url: '../team_index/index',
      })
    } else if (index == 2) {
      wx.navigateTo({
        url: '../canvas_index/index',
      })
    }
    else if (index == 3) {
      wx.navigateTo({
        url: '../exam/exam',
      })
    }
    // else if (index == 3) {
    //   wx.navigateTo({
    //     url: '../exam_marking/exam_marking',
    //   })
    // }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      list_height: getApp().globalData.windowHeight * 0.85,
      setting_btn_height: getApp().globalData.windowHeight * 0.1,
      role: options.type
    })

    wx.login({
      success: function (res) {
        if (res.code) {
          //获得本系统中的用户信息
          wx.request({
            url: getApp().globalData.my_server + "/hackson/getUserInfo",
            data: {
              code: res.code
            },
            method: "POST",
            header: {
              "Content-Type": "application/x-www-form-urlencoded"
            },
            success: function (res) {
              console.log(res)
              if (res.data.error_no != 0) {
                wx.showModal({
                  title: '哎呀～',
                  content: res.data.error_msg,
                  success: function (res) {
                    if (res.confirm) {
                      console.log('用户点击确定')
                    } else if (res.cancel) {
                      console.log('用户点击取消')
                    }
                  }
                })
              } else if (res.data.error_no == 0) {
                getApp().globalData.kind = res.data.type
                getApp().globalData.user = res.data.user
                console.log(getApp().globalData.kind, getApp().globalData.user)
              }
            },
            fail: function (res) {
              wx.showModal({
                title: '哎呀～',
                content: '获得用户信息失败',
                success: function (res) {
                  if (res.confirm) {
                    console.log('用户点击确定')
                  } else if (res.cancel) {
                    console.log('用户点击取消')
                  }
                }
              })
              console.log("fail!", res)
            },
            complete: function (res) {

            }
          })
        } else {
          console.log('登录失败！' + res.errMsg)
          wx.showModal({
            title: '哎呀～',
            content: '登录失败！',
            success: function (res) {
              if (res.confirm) {
                console.log('用户点击确定')
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })
        }
      }
    });

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})